package com.market.controller.admin;

import com.market.bean.MarketChannel;
import com.market.bean.MarketOrder;
import com.market.bean.common.BasePageInfo;
import com.market.bean.common.BaseRespVo;
import com.market.bean.common.CommonData;
import com.market.bean.vo.admin.AdminOrderDetailVO;
import com.market.service.admin.AdminOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: OrderController
 * @description: TODO :
 * @author: March
 * @version: 1.0
 * @datetime: 2022/12/28 21:07
 */
@RestController
@RequestMapping("admin/order")
public class AdminOrderController {

    @Autowired
    AdminOrderService orderService;

    /**
     * @description: 获取订单列表,当有搜索参数时,根据参数搜索并返回结果
     * @param info 分页信息
     * @param timeArray
     * @param start 开始时间
     * @param end 结束时间
     * @param orderId 订单编号
     * @param orderStatusArray 订单状态数组
     * @param userId 用户ID
     * @param orderSn 订单编号
     * @return com.market.bean.common.BaseRespVo
     * @author : Zqp
     * @version :
     * @date : 2022/12/31 23:21
     */
    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo info,
                           Date[] timeArray,
                           Date start,
                           Date end,
                           Integer orderId,
                           Short[] orderStatusArray,
                           Integer userId,
                           String orderSn){

        //订单编号不为空时,直接搜索并返回相应的订单信息
        if (orderId != null) {
            return BaseRespVo.ok();
        }

        //订单信息为空,则根据条件搜索
        CommonData<MarketOrder> data = orderService.list(info,timeArray,start,end,orderStatusArray,userId,orderSn);

        //结果为空,则返回提示信息
        if (data == null) {
            return BaseRespVo.systemError();
        }
        return BaseRespVo.ok(data);
    }

    /**
     * @description: 处理查看订单详情请求
     * @param id
     * @return com.market.bean.common.BaseRespVo
     * @author : Zqp
     * @version :
     * @date : 2022/12/31 22:14
     */
    @RequestMapping("detail")
    public BaseRespVo detail(Integer id){
        AdminOrderDetailVO data = orderService.getDetail(id);
        if (data != null) {
            return BaseRespVo.ok(data);
        }
        return BaseRespVo.systemError();
    }

    /**
     * @description: 处理发货操作
     * @param map
     * @return com.market.bean.common.BaseRespVo
     * @author : Zqp
     * @version :
     * @date : 2022/12/31 22:10
     */
    @RequestMapping("ship")
    public BaseRespVo ship(@RequestBody Map map){
        int code = orderService.shipOrder(map);
        if (code==1){
            return BaseRespVo.ok();
        }
        return BaseRespVo.systemError();
    }

    /**
     * @description: 处理删除订单的请求(逻辑删除)
     * @param map
     * @return com.market.bean.common.BaseRespVo
     * @author : Zqp
     * @version :
     * @date : 2023/1/2 9:02
     */
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map map){
        int code = orderService.deleteOrder(map);
        if (code == 1){
            return BaseRespVo.ok();
        }
        return BaseRespVo.systemError();
    }

    /**
     * @description: 处理订单的退款请求
     * @param map
     * @return com.market.bean.common.BaseRespVo
     * @author : Zqp
     * @version :
     * @date : 2023/1/2 9:03
     */
    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody Map map){
        int code = orderService.refund(map);
        if (code == 1){
            return BaseRespVo.ok();
        }
        return BaseRespVo.systemError();
    }

    /**
     * @description: 商品评论后台回复
     * @param map
     * @return com.market.bean.common.BaseRespVo
     * @author : Zqp
     * @version :
     * @date : 2023/1/3 10:01
     */
    @RequestMapping("reply")
    public BaseRespVo reply(@RequestBody Map map){
        int code = orderService.reply(map);
        if (code == 1){
            return BaseRespVo.ok();
        }
        return BaseRespVo.systemError();
    }

    /**
     * @description: 处理获取快递渠道的请求(获取到的是全部的快递渠道)
     * @return com.market.bean.common.BaseRespVo
     * @author : Zqp
     * @version :
     * @date : 2023/1/2 9:04
     */
    @RequestMapping("channel")
    public BaseRespVo channel(){
        List<MarketChannel> data = orderService.channel();
        return BaseRespVo.ok(data);
    }
}
